package com.xuan.bigdog.lib.location;

import android.content.Context;

import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;

/**
 * 百度定位工具类
 * 
 * @author xuan
 * 
 */
public class DGLocationUtils {
	private static LocationClient locationClient;

	/**
	 * 初始化
	 * 
	 * @param application
	 * @param l
	 */
	public static void init(Context application, BDLocationListener l) {
		locationClient = new LocationClient(application);
		locationClient.registerLocationListener(l);

		// 设置配置
		LocationClientOption option = new LocationClientOption();
		option.setLocationMode(LocationMode.Hight_Accuracy);// 高精度
		option.setCoorType("bd09ll");// gcj02：国测局加密坐标值，bd09ll:百度加密坐标值，bd09：百度加密墨卡托坐标
		option.setScanSpan(5000);// 5S定位一次
		option.setIsNeedAddress(true);// 是否需要反地理编码
		locationClient.setLocOption(option);
	}

	/**
	 * 开始定位
	 */
	public static void start() {
		checkNull();
		locationClient.start();
	}

	/**
	 * 结束定位
	 */
	public static void stop() {
		checkNull();
		locationClient.stop();
	}

	// 检查空
	private static void checkNull() {
		if (null == locationClient) {
			throw new NullPointerException("Call BGLocationUtils.init fisrt.");
		}
	}

}
